package cn.duckerkj.util;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class JsonTools {
	//ResultSet To Json
	public static final JSONArray ResultSetToJson(ResultSet rs) throws SQLException
	{
		JSONArray jsArray= new JSONArray();
			
		ResultSetMetaData rsmd = null;
		String columnName,columnValue=null;
		while(rs.next()) {
			JSONObject jsonObject1 = new JSONObject();
			rsmd = rs.getMetaData();
			for (int i = 0; i < rsmd.getColumnCount(); i++) {
                columnName = rsmd.getColumnLabel(i + 1);
                columnValue = rs.getString(columnName);
                columnValue = columnValue.replaceAll("bfh","%");// \u66ff\u6362% ssg
                jsonObject1.put(columnName, columnValue);
			}
			
			jsArray.add(jsonObject1);
			//System.out.println(jsonObject1.values());
		}
		return jsArray;
	}
}
